<template>
  <div class="h-full flex dt-page w-full p-3 flex-col">
    <div class="flex-1 p-3 bg-white">
      <DtTable @register="registerTable"></DtTable>
    </div>
  </div>
</template>

<script lang="ts" setup>
import { useTimeoutFn } from '@zm-pkg/core'
import { useTable } from '@zm-pkg/ui'


const dataSource = ref([])

const [registerTable] = useTable({
  rowKey: 'key',
  canResize: false,
  defaultExpandedRowKeys: [1, 11, 12],
  indentSize: 20,
  columns: [
    { title: '列1', dataIndex: 'name' },
    { title: '列2', dataIndex: 'age' },
  ],
  dataSource
})


function getData() {
  dataSource.value = [
    {
      key: 1,
      name: 'John Brown sr.',
      age: 60,
      address: 'New York No. 1 Lake Park',
      children: [
        {
          key: 11,
          name: 'John Brown',
          age: 42,
          address: 'New York No. 2 Lake Park',
        },
        {
          key: 12,
          name: 'John Brown jr.',
          age: 30,
          address: 'New York No. 3 Lake Park',
          children: [
            {
              key: 121,
              name: 'Jimmy Brown',
              age: 16,
              address: 'New York No. 3 Lake Park',
            },
          ],
        },
        {
          key: 13,
          name: 'Jim Green sr.',
          age: 72,
          address: 'London No. 1 Lake Park',
          children: [
            {
              key: 131,
              name: 'Jim Green',
              age: 42,
              address: 'London No. 2 Lake Park',
              children: [
                {
                  key: 1311,
                  name: 'Jim Green jr.',
                  age: 25,
                  address: 'London No. 3 Lake Park',
                },
                {
                  key: 1312,
                  name: 'Jimmy Green sr.',
                  age: 18,
                  address: 'London No. 4 Lake Park',
                },
              ],
            },
          ],
        },
      ],
    },
    {
      key: 2,
      name: 'Joe Black',
      age: 32,
      address: 'Sidney No. 1 Lake Park',
    },
  ];
}

onMounted(() => {
  useTimeoutFn(getData, 300)
})
</script>

<style lang="less" scoped>
:deep(.dt-table){
  height: 100%;
}
</style>